package com.enation.app.javashop.buyer.api.trade;

import com.enation.app.javashop.core.payment.model.enums.ClientType;
import com.enation.app.javashop.core.trade.order.model.vo.TradeVO;
import com.enation.app.javashop.core.trade.order.service.CheckoutParamManager;
import com.enation.app.javashop.core.trade.order.service.TradeManager;
import com.enation.app.javashop.core.trade.order.service.TradePriceManager;
import com.enation.app.javashop.framework.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 交易控制器
 *
 * @author Snow create in 2018/5/8
 * @version v2.0
 * @since v7.0.0
 */
@Api(description = "交易接口模块")
@RestController
@RequestMapping("/trade")
@Validated
public class TradeBuyerController {

    @Autowired
    private TradeManager tradeManager;

    @Autowired
    private CheckoutParamManager checkoutParamManager;

    @Autowired
    private TradePriceManager tradePriceManager;




    @ApiOperation(value = "创建交易")
    @PostMapping(value = "/create")
    @ApiImplicitParam(name = "client", value = "app下单使用，传值APP", required = false, dataType = "int", paramType = "path")
    public TradeVO create(String client) {

        String clientType;
        if (StringUtil.isWap()) {
            clientType = ClientType.WAP.name();
        } else if (ClientType.REACT.getClient().equals(client)) {

            clientType = ClientType.REACT.getClient();

        }else{
            clientType = ClientType.PC.name();
        }

        this.checkoutParamManager.setClientType(clientType);
        TradeVO tradeVO = this.tradeManager.createTrade();
        return tradeVO;
    }



}
